﻿//********************************************************************************//
//创建日期：<创建日期，2010-08-02>
//创建作者：<王一飞，wangyifei@shanghai3h.com>
//功能说明：AS_LOGINMSG实体层次
//********************************************************************************//

#region Entity

using System;
using System.Data;
using Entity;
using Oracle.DataAccess.Client;
using Platform.Configuration;
using Platform.Data;

namespace Entity
{
    [Serializable]
    public class AS_LOGINMSG
    {
        private decimal? m_dec_i_state;

        private decimal? m_dec_i_userid;

        private decimal m_dec_id;

        private DateTime? m_DT_d_time;

        private string m_str_s_miaoshu;

        /// <summary>
        ///     用户ID
        /// </summary>
        public decimal? I_USERID
        {
            get { return m_dec_i_userid; }
            set { m_dec_i_userid = value; }
        }

        /// <summary>
        ///     说明
        /// </summary>
        public string S_MIAOSHU
        {
            get { return m_str_s_miaoshu; }
            set { m_str_s_miaoshu = value; }
        }

        /// <summary>
        ///     时间
        /// </summary>
        public DateTime? D_TIME
        {
            get { return m_DT_d_time; }
            set { m_DT_d_time = value; }
        }

        /// <summary>
        ///     状态:0:在线 -1:下线
        /// </summary>
        public decimal? I_STATE
        {
            get { return m_dec_i_state; }
            set { m_dec_i_state = value; }
        }

        /// <summary>
        ///     主键
        /// </summary>
        public decimal ID
        {
            get { return m_dec_id; }
            set { m_dec_id = value; }
        }
    }
}

#endregion

#region EntityProcess

namespace BLL.Access
{
    //using System.Data.OracleClient;

    public class AS_LOGINMSGProcess
    {
        #region Field

        protected string conn;

        #endregion

        #region Construction

        public AS_LOGINMSGProcess()
        {
            conn = ConfigHelper.PlatformConnString;
        }

        #endregion

        #region public

        /// <summary>
        ///     根据AS_LOGINMSG实体添加或者修改AS_LOGINMSG信息
        /// </summary>
        public bool InsertOrUpdate(AS_LOGINMSG AS_LOGINMSG, OracleTransaction Transaction)
        {
            if (AS_LOGINMSG.ID == 0)
                InsertAS_LOGINMSG(AS_LOGINMSG, Transaction);
            else
                UpdateAS_LOGINMSG(AS_LOGINMSG, Transaction);
            return AS_LOGINMSG.ID == 0 ? false : true;
        }

        /// <summary>
        ///     根据AS_LOGINMSG实体添加或修改AS_LOGINMSG信息
        /// </summary>
        public bool InsertOrUpdate(AS_LOGINMSG AS_LOGINMSG)
        {
            return InsertOrUpdate(AS_LOGINMSG, null);
        }


        /// <summary>
        ///     根据AS_LOGINMSG主键删除AS_LOGINMSG信息
        /// </summary>
        /// <param name="ID"></param>
        public bool DeleteAS_LOGINMSG(decimal ID, OracleTransaction Transaction)
        {
            var spName = "CS_DelAS_LOGINMSG";
            var storedParams = OracleHelperParameterCache.GetSpParameterSet(conn, spName);
            storedParams[0].Value = ID;
            var result = 0;
            if (Transaction == null)
                result = OracleHelper.ExecuteNonQuery(conn, CommandType.StoredProcedure, spName, storedParams);
            else
                result = OracleHelper.ExecuteNonQuery(Transaction, CommandType.StoredProcedure, spName, storedParams);
            return result == 0 ? false : true;
        }

        /// <summary>
        ///     根据AS_LOGINMSG主键删除AS_LOGINMSG信息
        /// </summary>
        /// <param name="ID"></param>
        public bool DeleteAS_LOGINMSG(decimal ID)
        {
            return DeleteAS_LOGINMSG(ID, null);
        }

        /// <summary>
        ///     根据条件删除AS_LOGINMSG信息
        /// </summary>
        /// <param name="WhereClause">条件子句(Oracle语句)不带where</param>
        /// <param name="Transaction">事务，如果为null,则不做事务</param>
        /// <returns>如果删除成功，返回true,否则返回fals</returns>
        public bool DeleteAS_LOGINMSGsDynamic(string WhereClause, OracleTransaction Transaction)
        {
            var spName = "CS_DelAS_LOGINMSGsDyn";
            var storedParams = OracleHelperParameterCache.GetSpParameterSet(conn, spName);
            storedParams[0].Value = WhereClause;
            var result = 0;
            if (Transaction == null)
                result = OracleHelper.ExecuteNonQuery(conn, CommandType.StoredProcedure, spName, storedParams);
            else
                result = OracleHelper.ExecuteNonQuery(Transaction, CommandType.StoredProcedure, spName, storedParams);
            return result == 0 ? false : true;
        }

        /// <summary>
        ///     根据条件删除AS_LOGINMSG信息
        /// </summary>
        /// <param name="WhereClause">条件子句(Oracle语句)不带where</param>
        /// <param name="Transaction">事务，如果为null,则不做事务</param>
        /// <returns>如果删除成功，返回true,否则返回fals</returns>
        public bool DeleteAS_LOGINMSGsDynamic(string WhereClause)
        {
            return DeleteAS_LOGINMSGsDynamic(WhereClause, null);
        }

        /// <summary>
        ///     根据AS_LOGINMSG主键选择AS_LOGINMSG信息
        /// </summary>
        /// <param name="Transaction">事务，如果为null,则不做事务</param>
        /// <returns>AS_LOGINMSG信息</returns>
        public AS_LOGINMSG SelectAS_LOGINMSG(decimal ID, OracleTransaction Transaction)
        {
            var spName = "CS_SelAS_LOGINMSG";
            var storedParams = OracleHelperParameterCache.GetSpParameterSet(conn, spName);
            storedParams[0].Value = ID;
            OracleDataReader rd;
            if (Transaction == null)
                rd = OracleHelper.ExecuteReader(conn, CommandType.StoredProcedure, spName, storedParams);
            else
                rd = OracleHelper.ExecuteReader(Transaction, CommandType.StoredProcedure, spName, storedParams);
            if (rd.Read())
            {
                var AS_LOGINMSG = PopulateAS_LOGINMSG(rd);
                rd.Close();
                return AS_LOGINMSG;
            }
            return null;
        }

        /// <summary>
        ///     根据AS_LOGINMSG主键选择AS_LOGINMSG信息
        /// </summary>
        /// <returns>AS_LOGINMSG信息</returns>
        public AS_LOGINMSG SelectAS_LOGINMSG(decimal ID)
        {
            return SelectAS_LOGINMSG(ID, null);
        }

        /// <summary>
        ///     选择所有AS_LOGINMSG信息
        /// </summary>
        /// <param name="Transaction">事务，如果为null,则不做事务</param>
        /// <returns>所有AS_LOGINMSG信息</returns>
        public DataTable SelectAS_LOGINMSGsAll(OracleTransaction Transaction)
        {
            var spName = "CS_SelAS_LOGINMSGsAll";
            var storedParams = OracleHelperParameterCache.GetSpParameterSet(conn, spName);
            DataSet ds = null;
            if (Transaction == null)
                ds = OracleHelper.ExecuteDataset(conn, CommandType.StoredProcedure, spName, storedParams);
            else
                ds = OracleHelper.ExecuteDataset(Transaction, CommandType.StoredProcedure, spName, storedParams);
            if (ds != null && ds.Tables.Count > 0)
            {
                AddRowNumber(ds.Tables[0]);
                return ds.Tables[0];
            }
            return null;
        }

        /// <summary>
        ///     选择所有AS_LOGINMSG信息
        /// </summary>
        /// <returns>所有AS_LOGINMSG信息</returns>
        public DataTable SelectAS_LOGINMSGsAll()
        {
            return SelectAS_LOGINMSGsAll(null);
        }

        /// <summary>
        ///     根据条件选择AS_LOGINMSG信息
        /// </summary>
        /// <param name="WhereClause">条件子句(不带where)</param>
        /// <param name="OrderByExpression">排序子句</param>
        /// <param name="Transaction">事务，如果为null,则不做事务</param>
        /// <returns>AS_LOGINMSG信息</returns>
        public DataTable SelectAS_LOGINMSGsDynamic(string WhereClause, string OrderByExpression,
            OracleTransaction Transaction)
        {
            var spName = "CS_SelAS_LOGINMSGsDyn";
            var storedParams = OracleHelperParameterCache.GetSpParameterSet(conn, spName);
            storedParams[0].Value = string.IsNullOrEmpty(WhereClause.Trim()) ? "1=1" : WhereClause;
            storedParams[1].Value = OrderByExpression;
            DataSet ds = null;
            if (Transaction == null)
                ds = OracleHelper.ExecuteDataset(conn, CommandType.StoredProcedure, spName, storedParams);
            else
                ds = OracleHelper.ExecuteDataset(Transaction, CommandType.StoredProcedure, spName, storedParams);
            if (ds != null && ds.Tables.Count > 0)
            {
                AddRowNumber(ds.Tables[0]);
                return ds.Tables[0];
            }
            return null;
        }


        /// <summary>
        ///     根据条件选择AS_LOGINMSG信息
        /// </summary>
        /// <param name="WhereClause">条件子句(不带where)</param>
        /// <param name="OrderByExpression">排序子句</param>
        /// <returns>AS_LOGINMSG信息</returns>
        public DataTable SelectAS_LOGINMSGsDynamic(string WhereClause, string OrderByExpression)
        {
            return SelectAS_LOGINMSGsDynamic(WhereClause, OrderByExpression, null);
        }


        /// <summary>
        ///     根据条件选择AS_LOGINMSG信息
        /// </summary>
        /// <param name="WhereClause">条件子句(不带where)</param>
        /// <param name="OrderByExpression">排序子句</param>
        /// <param name="PageIndex">页码</param>
        /// <param name="PageSize">页数</param>
        /// <param name="Transaction">事务，如果为null,则不做事务</param>
        /// <returns>AS_LOGINMSG信息</returns>
        public DataTable SelectAS_LOGINMSGsDynamic(string WhereClause, string OrderByExpression, int PageIndex,
            int PageSize, OracleTransaction Transaction)
        {
            var spName = "CS_SelAS_LOGINMSGsDynPaged";
            var storedParams = OracleHelperParameterCache.GetSpParameterSet(conn, spName);
            storedParams[0].Value = string.IsNullOrEmpty(WhereClause.Trim()) ? "1=1" : WhereClause;
            storedParams[1].Value = OrderByExpression;
            storedParams[2].Value = PageIndex;
            storedParams[3].Value = PageSize;
            DataSet ds = null;
            if (Transaction == null)
                ds = OracleHelper.ExecuteDataset(conn, CommandType.StoredProcedure, spName, storedParams);
            else
                ds = OracleHelper.ExecuteDataset(Transaction, CommandType.StoredProcedure, spName, storedParams);
            if (ds != null && ds.Tables.Count > 0)
            {
                AddRowNumber(ds.Tables[0]);
                return ds.Tables[0];
            }
            return null;
        }


        /// <summary>
        ///     根据条件选择AS_LOGINMSG信息
        /// </summary>
        /// <param name="WhereClause">条件子句(不带where)</param>
        /// <param name="OrderByExpression">排序子句</param>
        /// <param name="PageIndex">页码</param>
        /// <param name="PageSize">页数</param>
        /// <returns>AS_LOGINMSG信息</returns>
        public DataTable SelectAS_LOGINMSGsDynamic(string WhereClause, string OrderByExpression, int PageIndex,
            int PageSize)
        {
            return SelectAS_LOGINMSGsDynamic(WhereClause, OrderByExpression, PageIndex, PageSize, null);
        }

        /// <summary>
        ///     根据条件更新AS_LOGINMSG字段
        /// </summary>
        /// <returns>受影响行数</returns>
        public int UpdateAS_LOGINMSGsDynamic(string UpdateValue, string WhereClause, OracleTransaction Transaction)
        {
            var result = 0;
            if (UpdateValue == "" || WhereClause == "")
                return 0;
            var spName = "CS_UpdAS_LOGINMSGDyn";
            var storedParams = OracleHelperParameterCache.GetSpParameterSet(conn, spName);
            DataSet ds = null;
            storedParams[0].Value = UpdateValue;
            storedParams[1].Value = WhereClause;
            if (Transaction == null)
                ds = OracleHelper.ExecuteDataset(conn, CommandType.StoredProcedure, spName, storedParams);
            else
                ds = OracleHelper.ExecuteDataset(Transaction, CommandType.StoredProcedure, spName, storedParams);
            result = Convert.ToInt32(storedParams[2].Value);
            return result;
        }

        /// <summary>
        ///     根据条件更新AS_LOGINMSG字段
        /// </summary>
        /// <returns>受影响行数</returns>
        public int UpdateAS_LOGINMSGsDynamic(string UpdateValue, string WhereClause)
        {
            return UpdateAS_LOGINMSGsDynamic(UpdateValue, WhereClause, null);
        }

        #endregion

        #region Private

        private int InsertAS_LOGINMSG(AS_LOGINMSG AS_LOGINMSG, OracleTransaction Transaction)
        {
            var spName = "CS_InsAS_LOGINMSG";
            var storedParams = OracleHelperParameterCache.GetSpParameterSet(conn, spName);
            storedParams[0].Value = AS_LOGINMSG.I_USERID;
            storedParams[1].Value = AS_LOGINMSG.S_MIAOSHU;
            storedParams[2].Value = AS_LOGINMSG.D_TIME;
            storedParams[3].Value = AS_LOGINMSG.I_STATE;
            var result = 0;
            if (Transaction == null)
                result = OracleHelper.ExecuteNonQuery(conn, CommandType.StoredProcedure, spName, storedParams);
            else
                result = OracleHelper.ExecuteNonQuery(Transaction, CommandType.StoredProcedure, spName, storedParams);
            AS_LOGINMSG.ID = Convert.ToInt32(storedParams[4].Value);
            return result;
        }

        private bool UpdateAS_LOGINMSG(AS_LOGINMSG AS_LOGINMSG, OracleTransaction Transaction)
        {
            var spName = "CS_UpdAS_LOGINMSG";
            var storedParams = OracleHelperParameterCache.GetSpParameterSet(conn, spName);
            storedParams[0].Value = AS_LOGINMSG.I_USERID;
            storedParams[1].Value = AS_LOGINMSG.S_MIAOSHU;
            storedParams[2].Value = AS_LOGINMSG.D_TIME;
            storedParams[3].Value = AS_LOGINMSG.I_STATE;
            storedParams[4].Value = AS_LOGINMSG.ID;
            var result = 0;
            if (Transaction == null)
                result = OracleHelper.ExecuteNonQuery(conn, CommandType.StoredProcedure, spName, storedParams);
            else
                result = OracleHelper.ExecuteNonQuery(Transaction, CommandType.StoredProcedure, spName, storedParams);
            return result == 0 ? false : true;
        }


        private AS_LOGINMSG PopulateAS_LOGINMSG(IDataReader dr)
        {
            var AS_LOGINMSG = new AS_LOGINMSG();
            AS_LOGINMSG.I_USERID = dr["I_USERID"] == DBNull.Value ? null : (decimal?) dr["I_USERID"];
            AS_LOGINMSG.S_MIAOSHU = dr["S_MIAOSHU"] == DBNull.Value ? null : (string) dr["S_MIAOSHU"];
            AS_LOGINMSG.D_TIME = dr["D_TIME"] == DBNull.Value ? null : (DateTime?) dr["D_TIME"];
            AS_LOGINMSG.I_STATE = dr["I_STATE"] == DBNull.Value ? null : (decimal?) dr["I_STATE"];
            AS_LOGINMSG.ID = dr["ID"] == DBNull.Value ? 0 : (decimal) dr["ID"];
            return AS_LOGINMSG;
        }


        private void AddRowNumber(DataTable dt)
        {
            dt.Columns.Add(new DataColumn("RowNumber", typeof(int)));
            for (var i = 0; i < dt.Rows.Count; i++)
                dt.Rows[i][dt.Columns.Count - 1] = i + 1;
        }

        #endregion
    }
}

#endregion